from rest_framework import serializers
from .models import Department,Position,Role


class DepartmentSerializer(serializers.ModelSerializer):
    class Meta:
        model = Department
        fields = '__all__'  # 取model中所有的字段。如果只是取部分，就 ("a","b") 元组的方式


class PositionSerializer(serializers.ModelSerializer):
    class Meta:
        model = Position
        fields = '__all__'  # 取model中所有的字段。如果只是取部分，就 ("a","b") 元组的方式


class RoleSerializer(serializers.ModelSerializer):
    department = DepartmentSerializer()  #序列化器嵌套，解决model的关联问题
    position = PositionSerializer()
    class Meta:
        model = Role
        fields = '__all__'  # 取model中所有的字段。如果只是取部分，就 ("a","b") 元组的方式

